﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;


namespace EnterpriseServices.Host
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : Installer
    {

        const string serviceName = "EntSvc"; // matches the name of WinSvc.ServiceName

        public ProjectInstaller()
        {
            InitializeComponent();
        }


        private void serviceInstaller_BeforeInstall(object sender, InstallEventArgs e)
        {

            //System.Security.Principal.WindowsIdentity.GetCurrent().Groups
            //foreach (DictionaryEntry entry in this.Context.Parameters)
            //    System.Diagnostics.EventLog.WriteEntry("EnterpriseServices.Host Installer",
            //        String.Format("{0} : {1}", entry.Key, entry.Value));

            //System.Security.Principal.WindowsIdentity.GetCurrent().Groups.Translate(typeof(System.Security.Principal.NTAccount)).ToList().ForEach(group =>
            //{
            //    Console.WriteLine(group.Value);
            //});

        }

        private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            try
            {
                System.ServiceProcess.ServiceController _svcController = new System.ServiceProcess.ServiceController(serviceName);
                _svcController.Start();
            }
            catch
            { }
        }

        private void ProjectInstaller_BeforeUninstall(object sender, InstallEventArgs e)
        {
            try
            {
                System.ServiceProcess.ServiceController _svcController = new System.ServiceProcess.ServiceController(serviceName);
                _svcController.Stop();
            }
            catch
            { }
        }

    }
}
